<?php
namespace cms\modules\v1\controllers;

use cms\modules\v1\models\access\ModuleActions;
use cms\modules\v1\models\circle\Circle;
use cms\modules\v1\models\circle\CircleComment;
use cms\modules\v1\models\feedback\FeedbackInfo;
use common\models\Functions;
use Yii;
use yii\base\BaseObject;
use yii\filters\auth\HttpHeaderAuth;
use yii\helpers\ArrayHelper;

/**
 * Default controller for the `v1` module
 */
class CircleController extends DefaultController
{

    public $modelClass = 'cms\modules\v1\models\im\ImUserLevel';

    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            'authenticator' => [
                'class' =>  HttpHeaderAuth::className(),    //head头部验证
                'header' => 'access-token',
                'optional' => [

                ]
            ]
        ]);
    }

    /* ====================== 朋友圈 ========================= */

    public function actionCircleList($page = 1, $size = 20){
        if (Yii::$app->request->isGet) {
            return (new Circle())->getListData($page, $size);
        }
    }
    //逻辑删除
    public function actionCircleDel() {
        $check = (new ModuleActions())->checkActions();
        if ($check !== true) {
            return Functions::formatRestAPI(1, $check);
        }
        if (Yii::$app->request->isGet) {
            return (new Circle())->getDelete();
        }
    }

    //设置成置顶
    public function actionExamine() {
        $check = (new ModuleActions())->checkActions();
        if ($check !== true) {
            return Functions::formatRestAPI(1, $check);
        }
        if (Yii::$app->request->isPost) {
            return (new Circle())->saveExamine();
        }
    }

    //待审核审核
    public function actionAudit() {
        if (Yii::$app->request->isGet) {
            return (new Circle())->queryAudit();
        }
    }

    //评论列表
    public function actionCommentList($page = 1, $size = 20){
        if (Yii::$app->request->isGet) {
            return (new CircleComment())->getListData($page, $size);
        }
    }

    //删除评论
    public function actionCommentDel() {
        $check = (new ModuleActions())->checkActions();
        if ($check !== true) {
            return Functions::formatRestAPI(1, $check);
        }
        if (Yii::$app->request->isGet) {
            return (new CircleComment())->getDelete();
        }
    }

    //审核提示音
    public function actionCommentAudit() {
        if (Yii::$app->request->isGet) {
            return (new CircleComment())->queryAudit();
        }
    }

    //评论审核
    public function actionCommentExamine() {
        $check = (new ModuleActions())->checkActions();
        if ($check !== true) {
            return Functions::formatRestAPI(1, $check);
        }
        if (Yii::$app->request->isPost) {
            return (new CircleComment())->saveExamine();
        }
    }


}
